package com.zhan.ielts.dao.impl;

import java.util.List;
import java.util.Map;

import com.zhan.frame.core.utils.BeanUtils;
import com.zhan.ielts.domain.query.SpeakingRecallQuery;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import com.zhan.frame.core.dao.impl.BaseDaoImpl;
import com.zhan.ielts.dao.SpeakingRecallDao;
import com.zhan.ielts.domain.SpeakingRecall;
import com.zhan.ielts.domain.vo.SpeakingRecallVo;

@Repository
public class SpeakingRecallDaoImpl extends BaseDaoImpl<SpeakingRecall> implements SpeakingRecallDao {

	@Override
	public List<SpeakingRecall> selectLatest(SpeakingRecallVo entity) {
		return sqlSessionTemplate.selectList(getSqlName("selectLatestOnes"), entity);
	}

	@Override
	public Integer countEveryDay(String userId) {
		return sqlSessionTemplate.selectOne(getSqlName("selectDaysCount"),userId);
	}


	@Override
	public Page<SpeakingRecallVo> selectReviewList(SpeakingRecall query, Pageable pageable) {

		List<SpeakingRecallVo> contentList = sqlSessionTemplate.selectList(getSqlName("selectReview"), getParams(query, pageable));
		Long count = sqlSessionTemplate.selectOne(getSqlName("selectReviewCount"), query);
		return new PageImpl<SpeakingRecallVo>(contentList, pageable, count == null ? 0 : count);
	}

	@Override
	public int selectUntreatedCount(SpeakingRecall query) {
		return sqlSessionTemplate.selectOne(getSqlName("selectUntreatedCount"), query);
	}

	@Override
	public List<SpeakingRecallVo> selectUnPushList(SpeakingRecall query) {
		Map<String, Object> params = BeanUtils.toMap(query);
		return sqlSessionTemplate.selectList(getSqlName("selectUnPushList"), params);
	}

}
